import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:jetour_line/base_widget/base_image.dart';

import '../my_colors.dart';
import 'package:flutter_cache_manager/flutter_cache_manager.dart';
class ImageNetworkWidget extends StatelessWidget {
  String url;
  final double placeholderWidth;
  final double width;
  final double height;
  final bool iShowLoading;
  final BoxFit fit;
  final int thumWidth;
  final int thumHeight;
  final double radius;

  ImageNetworkWidget(this.url,
      {this.placeholderWidth = 80,
        this.width = double.infinity,
        this.height = double.infinity,
        this.fit = BoxFit.cover,
        this.iShowLoading = true,
        this.thumHeight= 0,
        this.thumWidth = 0,
        this.radius = 0.0
      });
  @override
  Widget build(BuildContext context) {

    if (url != null && url.contains('v3img.ahatrip.net') && thumHeight >0 ) {
      //http://v3img.ahatrip.net/line/logo/202106/02-15/a65d3d822b7aed5659c6b1b12be6ea05.jpg@200x200
      String str = 'x';
      if (!url.contains('@$thumWidth$str$thumHeight')) {
        url = '$url@$thumWidth$str$thumHeight';
      }
    }
    // TODO: implement build
    return ClipRRect(
      borderRadius: BorderRadius.all(Radius.circular(radius)),
      child: CachedNetworkImage(
        // cacheManager: CacheManager( Config(
        //   'libCachedImageData',
        //   stalePeriod: const Duration(days: 7),
        //   maxNrOfCacheObjects: 20,
        //   repo: JsonCacheInfoRepository(databaseName: 'libCachedImageData'),
        //   fileService: HttpFileService(),
        // ),),
        width: width,
        height: height,
        fit: fit,
        imageUrl: url,
        placeholder: (context, url) => Container(

          width: placeholderWidth,
          height: placeholderWidth,
          child: (iShowLoading)
              ? Center(
            child: CircularProgressIndicator(
//                  value: 0,
              backgroundColor: MyColors.appColor,
              strokeWidth: 2,
            ),
          )
              : SizedBox(),
        ),
        errorWidget: (context, url, error) {
          return const Center(child:  BaseImage(image: 'error_img',),);
        },
      ),
    );
  }
}
